<template>
	<view>
		<!-- 搜索区域 -->
		<view class="box">
			<my-search @click.native="gotoSearch"></my-search>
		</view>
		<!-- 轮播图区域 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" circular>
			<swiper-item v-for="item in swiperList" :key="item.goods_.id">
				<!-- <navigator :url="'/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id" class="swiper-item"> -->
				<navigator :url="`/subpkg/goods_detail/goods_detail?goods_id=${item.goods_id}`" class="swiper-item">
					<image :src="item.image_src"></image>
				</navigator>
			</swiper-item>
		</swiper>

		<!-- nav导航 -->
		<view class="nav-list">
			<view class="nav-item" v-for="(item,i) in navList" :key="i" @click="gotoCate(i)">
				<image :src="item.image_src" class="nav-img"></image>
			</view>
		</view>

		<!-- 楼梯导航 -->
		<view class="floor-lit">
			<view class="floor-item" v-for="(item,i) in floorList" :key="i">
				<image class="floor-title" :src="item.floor_title.image_src"></image>
				<view class="floor-img-box">
					<navigator
						:url="`/subpkg/goods_list/goods_list?${item.product_list[0].navigator_url.split('?')[1]}`"
						class="left-img-box">
						<image :src="item.product_list[0].image_src"
							:style="{width:item.product_list[0].image_width+'rpx'}" mode="widthFix"></image>
					</navigator>
					<view class="right-img-box">
						<navigator :url="'/subpkg/goods_list/goods_list?'+itemt.navigator_url.split('?')[1]"
							class="right-img-item" v-for="(itemt,it) in item.product_list" :key="it" v-if="it!==0">
							<image :src="itemt.image_src" :style="{width:itemt.image_width+'rpx'}" mode="widthFix">
							</image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import tabbarMinxin from '../../mixins/tabbar.js'
	export default {
		mixins: [tabbarMinxin],
		data() {
			return {
				swiperList: [],
				navList: [],
				floorList: []
			};
		},
		onLoad() {
			this.getSwiperList()
			this.getNavList()
			this.getFloorList()
		},
		methods: {
			// 轮播图数据
			async getSwiperList() {
				const {
					data
				} = await uni.$http.get('/home/swiperdata')
				if (data.meta.status !== 200) return uni.$showToast()
				this.swiperList = data.message
			},

			// 获得导航数据
			async getNavList() {
				const {
					data
				} = await uni.$http.get('/home/catitems')
				if (data.meta.status !== 200) return uni.$showToast()
				this.navList = data.message
			},

			// 电梯导航数据
			async getFloorList() {
				const {
					data
				} = await uni.$http.get('/home/floordata')
				if (data.meta.status !== 200) return uni.$showToast()
				this.floorList = data.message
			},

			// 点击 分类导航 跳转tabbar的 cate 页面
			gotoCate(index) {
				if (index === 0) {
					uni.switchTab({
						url: '/pages/cate/cate'
					})
				}
			},
			gotoSearch() {
				uni.navigateTo({
					url: '/subpkg/search/search'
				})
			}
		}
	}
</script>

<style lang="scss">
	.box {
		position: sticky;
		top: 0;
		z-index: 999;
	}

	swiper {
		height: 330rpx;

		.swiper-item,
		image {
			width: 100%;
			height: 100%;
		}
	}

	.nav-list {
		display: flex;
		justify-content: space-around;
		margin: 15px 0;

		.nav-img {
			width: 128rpx;
			height: 140rpx;
		}
	}

	.floor-title {
		height: 60rpx;
		width: 100%;
		display: flex;
	}

	.right-img-box {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
	}

	.floor-img-box {
		display: flex;
		padding-left: 10rpx;
	}
</style>